﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OAuth.Sina
{
    public class SinaOAuthMode : IOAuthMode
    {
        private SinaOAuthConfig config = new SinaOAuthConfig();
        private OAuthParameter _OAuthCallBack;
        private OAuthParameter OAuthNonce = new OAuthParameter("oauth_nonce", OAuthCommon.GetOAuthNonce());
        private OAuthParameter OAuthTimeStamp = new OAuthParameter("oauth_timestamp", OAuthCommon.GetOAuthTimeStamp());
        private OAuthParameter OAuthSignature;
        private OAuthParameter _OAuthToken;
        private OAuthParameter _OAuthTokenSecret;
        private OAuthParameter _OAuthVerifier;

        /// <summary>
        /// 设置回调地址
        /// </summary>
        /// <param name="CallBackURL"></param>
        public void SetOAuthCallBack(Uri CallBackURL)
        {
            _OAuthCallBack = new OAuthParameter("oauth_callback", CallBackURL.ToString());
        }

        /// <summary>
        /// 得到回调地址
        /// </summary>
        /// <returns></returns>
        public OAuthParameter GetOAuthCallBack()
        {
            if (_OAuthCallBack == null)
            {
                _OAuthCallBack = new OAuthParameter("oauth_callback", config.GetCallBackURI().ToString());
            }
            return _OAuthCallBack;
        }

        /// <summary>
        /// 得到申请的ConsumerKey
        /// </summary>
        /// <returns></returns>
        public OAuthParameter GetOAuthConsumerKey()
        {
            return new OAuthParameter("oauth_consumer_key", config.GetAppKey());
        }

        /// <summary>
        /// 设置随机字符串
        /// </summary>
        /// <param name="OAuthNoncd"></param>
        public void SetOAuthNonce(string OAuthNonceString)
        {
            OAuthNonce = new OAuthParameter("oauth_nonce", OAuthNonceString);
        }

        /// <summary>
        /// 得到随机字符串
        /// </summary>
        /// <returns></returns>
        public OAuthParameter GetOAuthNonce()
        {
            return OAuthNonce;
        }

        /// <summary>
        /// 得到签名方式
        /// </summary>
        /// <returns></returns>
        public OAuthParameter GetOAuthSignatureMethod()
        {
            return new OAuthParameter("oauth_signature_method", "HMAC-SHA1");
        }

        public void SetOAuthTimeStamp(string OAuthTimeStampString)
        {
            OAuthTimeStamp = new OAuthParameter("oauth_timestamp", OAuthTimeStampString);
        }

        /// <summary>
        /// 得到时间戳
        /// </summary>
        /// <returns></returns>
        public OAuthParameter GetOAuthTimeStamp()
        {
            return OAuthTimeStamp;
        }

        /// <summary>
        /// 得到OAuth版本
        /// </summary>
        /// <returns></returns>
        public OAuthParameter GetOAuthVersion()
        {
            return new OAuthParameter("oauth_version", "1.0a");
        }

        /// <summary>
        /// 设置签名字符串
        /// </summary>
        /// <param name="OAuthSignatureString"></param>
        public void SetOAuthSignature(string OAuthSignatureString)
        {
            OAuthSignature = new OAuthParameter("oauth_signature", OAuthSignatureString);
        }

        /// <summary>
        /// 得到签名字符串
        /// </summary>
        /// <returns></returns>
        public OAuthParameter GetOAuthSignature()
        {
            return OAuthSignature;
        }

        /// <summary>
        /// 设置Sina的OAuthToken
        /// </summary>
        /// <param name="OAuthToken"></param>
        public void SetOAuthToken(OAuthParameter OAuthToken)
        {
            _OAuthToken = OAuthToken;
        }

        /// <summary>
        /// 得到Sina的OAuthToken
        /// </summary>
        /// <returns></returns>
        public OAuthParameter GetOAuthToken()
        {
            return _OAuthToken;
        }

        /// <summary>
        /// 设置Sina的OAuthTokenSecret
        /// </summary>
        /// <param name="OAuthTokenSecret"></param>
        public void SetOAuthTokenSecret(OAuthParameter OAuthTokenSecret)
        {
            _OAuthTokenSecret = OAuthTokenSecret;
        }

        /// <summary>
        /// 得到Sina的OAuthTokenSecret
        /// </summary>
        /// <returns></returns>
        public OAuthParameter GetOAuthTokenSecret()
        {
            return _OAuthTokenSecret;
        }

        /// <summary>
        /// 设置OAuthVerifier
        /// </summary>
        /// <param name="OAuthVerifier"></param>
        public void SetOAuthVerifier(OAuthParameter OAuthVerifier)
        {
            _OAuthVerifier = OAuthVerifier;
        }

        /// <summary>
        /// 得到OAuthVerifier
        /// </summary>
        /// <returns></returns>
        public OAuthParameter GetOAuthVerifier()
        {
            return _OAuthVerifier;
        }

        /// <summary>
        /// 得到接口提供高
        /// </summary>
        /// <returns></returns>
        public OAuthEnum.OAuthInterface GetOAuthInterface()
        {
            return OAuthEnum.OAuthInterface.Sina;
        }
    }
}
